<?php
	class Cards extends CI_Controller{
	
		private $deck = [];
		private $trump = [];
		private $card = [];
		
		function __construct(){
			parent::__construct();
			$this->deck = $this->durak_model->getDeck();
			$this->shuffleDeck();
		}
		
		function getAllDeck(){
			$deck = array(
					'deck' => $this->deck,
					'trump' => $this->trump,
					'card' => $this->card
				);
			return $deck;
		}
		
		function setAllDeck($deck){
			$this->deck = $deck['deck'];
			$this->trump = $deck['trump'];
			$this->card = $deck['card'];
		}
		
		function initDeck(){
			$this->deck = $this->durak_model->getDeck();
		}
		
		function initShuffleDeck(){
			$this->deck = $this->durak_model->getDeck();
			$this->shuffleDeck();
		}
		
		function initTrump(){
			$deck = $this->deck;
			$this->trump = array_pop($deck);
			$this->deck = $deck;
		}
		
		function getDeck(){
			return $this->deck;
		}
		
		function getDeckCount(){
			return count($this->deck);
		}
		
		function getTrump(){
			return $this->trump;
		}
		
		function getCard(){
			return $this->card;
		}
		
		function setDeck($deck){
			$this->deck = $deck;
		}
		
		function setTrump($trump){
			$this->trump = $trump;
		}
		
		function setCard($card){
			$this->card = $card;
		}
		
		function shuffleDeck(){
			$deck = $this->deck;
			shuffle($deck);
			$this->deck = $deck;
		}
		
		function drawCard(){
			$deck = $this->deck; 
			$card = array_pop($deck);
			$this->deck = $deck; 
			$this->session->set_userdata('deck', $this->getAllDeck());
			return $card;
		}
	}
?>